<template>
  <div class="user">
    <template v-if="!user">
      <div class="My_title">
        <img src="http://liufusong.top:8080/img/profile/bg.png" alt="" />
        <div class="My_info">
          <div class="My_myIcon">
            <img
              class="My_avatar"
              src="http://liufusong.top:8080/img/profile/avatar.png"
              alt=""
            />
          </div>
          <div class="My_user">
            <div class="My_name">好客租房</div>

            <div class="My_edit">
              <van-button to="/login" type="primary">去登录</van-button>
            </div>
          </div>
        </div>
      </div>
      <my-info></my-info>
    </template>
    <template v-else>
      <div class="My_title">
        <img src="http://liufusong.top:8080/img/avatar.png" alt="" />
        <div class="My_info">
          <div class="My_myIcon">
            <img
              class="My_avatar"
              src="http://liufusong.top:8080/img/profile/avatar.png"
              alt=""
            />
          </div>
          <div class="My_user">
            <div class="My_name">好客租房</div>
            <div class="My_auth">
              <span @click="onLogout">退出</span>
            </div>
            <div class="My_edit">
              "编辑个人资料"
              <span>
                <van-icon name="share-o" />
              </span>
            </div>
          </div>
        </div>
      </div>
      <my-info></my-info>
    </template>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { Dialog } from 'vant'
import MyInfo from './components/MyInfo'

export default {
  components: { MyInfo },
  name: 'My',
  data () {
    return {}
  },

  created () {},
  computed: {
    ...mapState(['user'])
  },
  methods: {
    onLogout () {
      Dialog.confirm({
        title: '好客租房系统',
        message: '是否退出登录！'
      })
        .then(() => {
          // on confirm
          this.$store.commit('removeUser')
        })
        .catch(() => {
          // on cancel
        })
    }
  }
}
</script>

<style scoped lang="less">
.user {
  .My_title {
    min-height: 300px;
    position: relative;
    img {
      width: 100%;
    }
    .My_info {
      position: absolute;
      background: #fff;
      width: 75%;
      height: 55%;
      bottom: 0;
      left: 50%;
      transform: translateX(-50%);
      box-shadow: 0 0 10px 3px #ddd;
      margin: 50px auto 0;
      padding: 0 20px;
      text-align: center;
      font-size: 13px;
      margin-bottom: 7px;
      .My_myIcon {
        position: relative;
        transform: translateY(-50%);
        border-radius: 50%;
        width: 70px;
        height: 70px;
        border: 5px solid #f5f5f5;
        display: inline-block;
        box-shadow: 0 2px 2px #bdbdbd;
        .My_avatar {
          width: 100%;
          border-radius: 50%;
        }
      }
      .My_user {
        padding-top: 15px;
        .My_name {
          margin-top: -30px;
          margin-bottom: 10px;
        }
      }
      .My_auth {
        margin-bottom: 30px;
        span {
          border-radius: 30px;
          color: #fff;
          padding: 2px 15px;
          background: #21b97a;
          font-size: 12px;
        }
      }
      .My_edit {
        color: #999;
        font-size: 12px;
        margin-top: 20px;
        .van-button {
          width: 69px;
          height: 30px;
          font-size: 12px;
          border-radius: 5px;
        }
      }
    }
  }
  .My_ad {
    text-align: center;
    margin-top: 10px;
    img {
      width: 90%;
    }
  }
}
</style>
